package cn.edu.bzu.manager.computer.controller;

import cn.edu.bzu.manager.computer.service.AllComponentService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 所有配件的控制器
 * 返回类型均为JSON类型
 *
 * @author 1923111017张铭宸
 * @since 1.8
 */

@RestController
@AllArgsConstructor
@RequestMapping("/component")
public class ComponentController {

    private final AllComponentService allComponentService;

    /**
     * GET
     *
     * @param typeId 硬件类型ID
     * @return 所有该类型的集合
     */
    @GetMapping(value = "/all", params = "typeId")
    public List<?> showAllComponent(Integer typeId) {
        return allComponentService.findAllComponentInfosByTypeId(typeId);
    }

    /**
     * GET
     * 根据硬件类型ID和配件ID号获取配件信息
     *
     * @param typeId      配件类型
     * @param componentId 配件类型对应配件表的ID
     * @return 满足的该配件，否则返回null
     */
    @GetMapping(value = "/", params = {"typeId", "componentId"})
    public Object showComponent(Integer typeId, Integer componentId) {
        return allComponentService.findComponentInfoByTypeIdAndComponentId(typeId, componentId);
    }

}
